package com.ikkong.over.controller;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.ikkong.core.base.BaseController;
import com.ikkong.core.dao.Blade;
import com.ikkong.core.jfinal.ext.kit.JsonKit;
import com.ikkong.myproject.controller.MyprojectController;
import com.ikkong.myproject.model.Myproject;
import com.ikkong.projects.model.Projects;
import com.ikkong.system.controller.base.UrlPermissController;
import com.ikkong.over.model.Over;
import com.ikkong.over.service.OverService;
import com.ikkong.over.service.impl.OverServiceImpl;
import com.ikkong.system.model.Dept;
import com.jfinal.upload.UploadFile;

/**
 * Generated by Blade.
 * 2018-04-11 21:06:03
 */
public class OverController extends UrlPermissController {
	private static String CODE = "over";
	private static String PERFIX = "over";
	private static String LIST_SOURCE = "Over.list";
	private static String BASE_PATH = "/platform/over/";
	
	OverService service = new OverServiceImpl();
	
	public void index() {
		setAttr("code", CODE);
		render(BASE_PATH + "over.html");
	}

	public void add() {
		setAttr("code", CODE);
		render(BASE_PATH + "over_add.html");
	}

	public void edit() {
	}
    public void exam() {
        setAttr("code", CODE);
        render(BASE_PATH + "over_by_com.html");
    }
    public void down() {
        String para = getPara("value");
        if(para != null && !"null".equals(para)){
            renderFile(para);
        }else {
            renderText("没有找到此文件");
        }


    }

	public void view() {
		String id = getPara("id");
        Projects pro = Blade.create(Projects.class).findById(id);
        Dept dept = Blade.create(Dept.class).findById(pro.getDept_id());
        setAttr("pro",pro);
        setAttr("dept",dept.getFullname());
		setAttr("code", CODE);
		render(BASE_PATH + "over_view.html");
	}

	public void list() {
		Object grid = paginate(LIST_SOURCE);
		renderJson(grid);
	}

	public void save() {
        UploadFile scheme1 = getFile("scheme");
        UploadFile batck1 = getFile("batch");
        UploadFile setting_up1 = getFile("setting_up");
        UploadFile test_run1 = getFile("test_run");
        UploadFile over1 = getFile("over");
        UploadFile supervision1 = getFile("supervision");
        UploadFile others1 = getFile("others");
        String scheme = "";
        String batch ="";
        String setting_up ="";
        String test_run ="";
        String overname = "";
        String supervision = "";
        String others ="";
        if(scheme1 != null){
            scheme = scheme1.getFileName();
        }
        if(batck1 != null){
           batch = batck1.getFileName();
        }
        if(setting_up1 != null){
            setting_up = setting_up1.getFileName();
        }
        if(test_run1 != null){
            test_run = test_run1.getFileName();
        }
        if(over1 != null){
            overname = over1.getFileName();
        }
        if(supervision1 != null){
            supervision = supervision1.getFileName();
        }
        if(others1 != null){
           others = others1.getFileName();
        }

        Over over = mapping(PERFIX, Over.class);
        over.setScheme(scheme);
        over.setBatch(batch);
        over.setSetting_up(setting_up);
        over.setTest_run(test_run);
        over.setOver(overname);
        over.setSupervision(supervision);
        over.setOthers(others);
        Myproject myproject = new Myproject();
        myproject.setId(over.getPro_id());
        myproject.setStatus(19);
        Blade.create(Myproject.class).update(myproject);
		boolean temp = service.save(over);
		if (temp) {
			renderJson(success(SAVE_SUCCESS_MSG));
		} else {
			renderJson(error(SAVE_FAIL_MSG));
		}
	}

	public void update() {
		Over over = mapping(PERFIX, Over.class);
		boolean temp = service.update(over);
		if (temp) {
			renderJson(success(UPDATE_SUCCESS_MSG));
		} else {
			renderJson(error(UPDATE_FAIL_MSG));
		}
	}

	public void remove() {
		String ids = getPara("ids");
		int cnt = service.deleteByIds(ids);
		if (cnt > 0) {
			renderJson(success(DEL_SUCCESS_MSG));
		} else {
			renderJson(error(DEL_FAIL_MSG));
		}
	}
}
